local skel = fk.CreateSkill{
  name = "lb__xunshu",
  tags = {Skill.Compulsory}
}
local U = require "packages.utility.utility"

Fk:loadTranslationTable{
  ["lb__xunshu"] = "寻赎",
  [":lb__xunshu"] = "<b>锁定技</b>，准备阶段，你依次亮出牌堆顶的牌直至出现<font color=#CC3131><b>♥</b></font>牌，然后获得其中一种花色的所有牌。",

  ["#lb__xunshu"] = "寻赎：请获得其中一组牌",

  ["$lb__xunshu1"] = "此世如雨而逝，终归大地…",
  ["$lb__xunshu2"] = "为寻索，为顿悟，为存在。	",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = {}
    repeat
      local id = room:getNCards(1)[1]
      room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, skel.name, nil, true, player)
      table.insert(ids, id)
      room:delay(200)
    until Fk:getCardById(id).suit == Card.Heart
    ids = table.filter(ids, function (id)
      return room:getCardArea(id) == Card.Processing
    end)
    if #ids > 0 then
      local listCards = {}
      for i = 1, 4, 1 do
        listCards[i] = table.filter(ids, function (id)
          return Fk:getCardById(id).suit == i
        end)
      end
      local listNames = { "log_spade", "log_club", "log_heart", "log_diamond" }
      local choices = U.askForChooseCardList(room, player, listNames, listCards, 1, 1, skel.name, "#lb__xunshu", false, false)
      if #choices > 0 then
        local cards = listCards[table.indexOf(listNames, choices[1])]
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, skel.name, nil, true, player)
        if Fk:getCardById(cards[1]).suit ~= Card.Heart then
          room:setPlayerMark(player, "lb__xunshu-turn", 1)
        end
      end
    end
    room:cleanProcessingArea()
  end,
})

return skel